#Boa:Frame:Frame1

import wx
from CONTROLE import *
from menuFrame import *
from menuCaixaFrame import *
def create(parent):
    return Frame1(parent)

[wxID_FRAME1, wxID_FRAME1BT_ENTRAR, wxID_FRAME1STATICBITMAP1, 
 wxID_FRAME1STATIC_LOGIN, wxID_FRAME1STATIC_SENHA, wxID_FRAME1TXT_LOGIN, 
 wxID_FRAME1TXT_SENHA, 
] = [wx.NewId() for _init_ctrls in range(7)]



senha_real = ""
class Frame1(wx.Frame):
    def _init_ctrls(self, prnt):
        # generated method, don't edit
        wx.Frame.__init__(self, id=wxID_FRAME1, name='', parent=prnt,
              pos=wx.Point(695, 245), size=wx.Size(158, 315),
              style=wx.DEFAULT_FRAME_STYLE, title=u'suPymercado')
        self.SetClientSize(wx.Size(142, 277))

        self.static_login = wx.StaticText(id=wxID_FRAME1STATIC_LOGIN,
              label=u'Usu\xe1rio:', name=u'static_login', parent=self,
              pos=wx.Point(26, 136), size=wx.Size(89, 25), style=0)
        self.static_login.SetFont(wx.Font(16, wx.SWISS, wx.NORMAL, wx.BOLD,
              False, u'Tahoma'))
        self.static_login.Center(wx.HORIZONTAL)

        self.txt_senha = wx.TextCtrl(id=wxID_FRAME1TXT_SENHA, name=u'txt_senha',
              parent=self, pos=wx.Point(0, 216), size=wx.Size(144, 24), style=0,
              value=u'1')
        self.txt_senha.Center(wx.HORIZONTAL)
        self.txt_senha.Bind(wx.EVT_TEXT, self.OnTxt_senhaText,
              id=wxID_FRAME1TXT_SENHA)

        self.static_senha = wx.StaticText(id=wxID_FRAME1STATIC_SENHA,
              label=u'Senha:', name=u'static_senha', parent=self,
              pos=wx.Point(35, 192), size=wx.Size(72, 25), style=0)
        self.static_senha.SetFont(wx.Font(16, wx.SWISS, wx.NORMAL, wx.BOLD,
              False, u'Tahoma'))
        self.static_senha.Center(wx.HORIZONTAL)

        self.txt_login = wx.TextCtrl(id=wxID_FRAME1TXT_LOGIN, name=u'txt_login',
              parent=self, pos=wx.Point(0, 160), size=wx.Size(144, 24), style=0,
              value=u'1')
        self.txt_login.SetToolTipString(u'textCtrl1')

        self.bt_entrar = wx.Button(id=wxID_FRAME1BT_ENTRAR, label=u'Entrar',
              name=u'bt_entrar', parent=self, pos=wx.Point(33, 248),
              size=wx.Size(75, 23), style=0)
        self.bt_entrar.Center(wx.HORIZONTAL)
        self.bt_entrar.Bind(wx.EVT_BUTTON, self.OnBt_entrarButton,
              id=wxID_FRAME1BT_ENTRAR)

        self.staticBitmap1 = wx.StaticBitmap(bitmap=wx.Bitmap(u'C:/Users/nb/Documents/pySupymercado/Src/carr.png',
              wx.BITMAP_TYPE_PNG), id=wxID_FRAME1STATICBITMAP1,
              name='staticBitmap1', parent=self, pos=wx.Point(7, 0),
              size=wx.Size(128, 128), style=0)
        self.staticBitmap1.Center(wx.HORIZONTAL)

    def __init__(self, parent):
        
        self._init_ctrls(parent)
       

    def OnBt_entrarButton(self, event):
        #coloca validador de login     
        self.txt_login.GetValue()
        senha_real
        c = Controle()
        usuario = c.validar_login(self.txt_login.GetValue(),senha_real)
        if usuario != False:
            if usuario.get_cargo() == 'GERENTE':
                menu = mainFrame(None, usuario)
        #menu = caixaFrame(None)
                menu.Show()
                self.Close()
            elif usuario.get_cargo() == 'CAIXA':
                menu = menuCaixaFrame(None, usuario)
        #menu = caixaFrame(None)
                menu.Show()
                self.Close()
        else:
            print 'usuario nao cadastrado'
            
            



    def OnTxt_senhaText(self, event):
        senha_protegida = ""
        for letra in self.txt_senha.GetValue():
            global senha_real
            if letra != '*':
                senha_real = senha_real+letra
            senha_protegida = senha_protegida+"*"
        self.txt_senha.SetValue(senha_protegida)
        #global senha_real = senha
        
    
        

